package org.whatisjava.action;

import java.util.ArrayList;
import java.util.List;

import org.whatisjava.action.test.Phone;

/**
 * 测试表单提交多个对象，转换问题
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-1-27
 */
public class TestConvertAction extends BaseAction {

	private static final long serialVersionUID = -8951706530503741957L;
	private List<Phone> phoneList = new ArrayList<Phone>();

	public List<Phone> getPhoneList() {
		return this.phoneList;
	}

	public void setPhoneList(List<Phone> phoneList) {
		this.phoneList = phoneList;
	}

	/**
	 * 请求页面
	 * 
	 * @return
	 */
	public String execute() {

		// Create Object
		for (int i = 1; i <= 5; i++) {
			Phone iPhone = new Phone("iphone:" + i, "No.:" + i, i
					* Math.random() * 1000 + "");
			phoneList.add(iPhone);
		}
		// iterator show list
		for (Phone p : phoneList) {
			System.out.println("brand:" + p.getBrand() + ",model:"
					+ p.getModel() + ",price:" + p.getPrice());
		}

		return "success";
	}

	/**
	 * 转换方法
	 * 
	 * @return
	 */
	public String convert() {
		if (phoneList != null) {
			for (Phone p : phoneList) {
				System.out.println("brand:" + p.getBrand() + ",model:"
						+ p.getModel() + ",price:" + p.getPrice());
			}
		}
		return "success";
	}
}
